    // https://www.luogu.com.cn/problem/P2871
    #include <algorithm>
    #include <cstring>
    #include <iostream>

    using namespace std;
    using ll = long long;
    const int inf = 0x3f3f3f3f;
    #define rf(i, n) for (int i = 1; i <= (n); ++i)
    #define MAX_SIZE 13005
    #define MAXN 3405

    int n, m;
    int p[MAXN], v[MAXN];
    int f[2][MAX_SIZE]; // f[i][j]: 前 i 个物品，容量不超过 j 时的最大价值

    int main() {
        scanf("%d%d", &n, &m);
        rf(i, n) scanf("%d%d", &v[i], &p[i]);

        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= m; ++j) {
                f[i % 2][j] = f[(i - 1) % 2][j];
                if (j >= v[i]) f[i % 2][j] = max(f[i % 2][j], f[(i - 1) % 2][j - v[i]] + p[i]);
            }
        }

        // rf(i, n) {
        //     rf(j, m) printf("%d ", f[i][j]);
        //     puts("");
        // }

        int ans = 0;
        rf(j, m) ans = max(ans, f[n % 2][j]);
        printf("%d", ans);
    }
